import React, { Component } from 'react'
import MyNavBar from '../../components/MyNavBar'
import HouseLtem from '../../components/HouseLtem'
import NoHouse from '../../components/NoHouse'
import { getuserHousesod } from '../../api/index'
import styles from './index.module.scss'
import { isLogin } from '../../utils/auth'
import { Link } from 'react-router-dom'
export default class CitySelect extends Component {
  state = {
    // 出租房屋列表
    list: []
  }
 async componentDidMount(){
  const isAuth =  isLogin()
  if(isAuth){
    const res = await getuserHousesod()
    const { status, body } = res.data
    console.log(body);
    if (status === 200) {
      this.setState({
        list: body
      })
    } else {
      const { history, location } = this.props
      history.replace('/login', {
        from: location
      })
    }
  }
   
  }
  renderRentList = () => {
    const { list } = this.state
    const hasHouses = list.length > 0

    if (!hasHouses) {
      return (
        <NoHouse>
          您还没有房源，
          <Link to="/rent/add" className={styles.link}>
            去发布房源
          </Link>
          吧~
        </NoHouse>
      )
    }
    return <div className={styles.houses}>
      {list.map(item => (
        <HouseLtem key={item.houseCode} {...item}></HouseLtem> 
      ))}
    </div>
  }
  render() {
    return (
      <div className={styles.room}>
        <div style={{height:'45px'}}><MyNavBar>房屋管理</MyNavBar></div>
        {this.renderRentList()}
      </div>
    )
  }
}
